package family;

/**
 * This program based on the Model-Viewer-Controller architecture 
 * and this is the main class which 
 *  - creates the object 'mainProgram' 
 *  - creates object of 'Model', 'View' and 'Controller' 
 *  - contains getter for 'mainProgram' 
 *  - contains method to end the mainProgram
 * 
 * @author Edis Dilji
 * @version 5.0, December 23, 2012
 */

// CLASSDEFINITION
public class Main {

	// reserve object 'mainProgram'
	protected static Main mainProgram;

	// reserve objects of 'Model', 'View' and 'Controller'
	private Model model;
	private View view;
	@SuppressWarnings("unused")
	private Controller controller;

	// *******************************************************************
	// MAIN-METHOD
	// *******************************************************************
	
	// main-method create only the first object 'mainProgram' for the GUI
	// and start the help-method for the console interaction
	public static void main(String[] args) {

		// Singleton pattern
		if (mainProgram == null) {
			mainProgram = new Main(); // new main Program for GUI
			mainProgram.model.help(); // new main Program starts help-method for console
		}
	}

	/**
	 * Main Class constructor.
	 */
	
	private Main() {
		// create components
		model = new Model();
		view = new View(model);
		controller = new Controller(model, view);
	}

	// getter MainProgram
	protected static Main getMainProgram() {
		return mainProgram;
	}

	// handling to end program
	protected void endMainProgram() {
		view.setVisible(false);
		System.out.println("The program has successfully stopped!");
		System.exit(0);
	}

}